package com.cci.kangdao.service;

import com.cci.kangdao.utilTool.GDRegion;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author William Du
 * @date 2019/9/27
 */
public abstract class AddressConverter {

    public static Map<String, Object> getAddressInfo(String address) {
        Map<String, Object> addressMap = GDRegion.getAddressInfo(address);
        if (MapUtils.isNotEmpty(addressMap)) {
            String adCode = MapUtils.getString(addressMap, "adCode");
            if (StringUtils.isNotEmpty(adCode)) {
                String city = MapUtils.getString(addressMap, "city");
                // 过滤特殊区域码，映射为系统需要信息
                if (adCode.startsWith("1101")) {
                    city = "北京城区";
                } else if (adCode.startsWith("1201")) {
                    city = "天津城区";
                } else if (adCode.startsWith("3101")) {
                    city = "上海城区";
                } else if (adCode.startsWith("5001")) {
                    city = "重庆城区";
                } else if (adCode.startsWith("5002")) {
                    city = "重庆郊县";
                }
                addressMap.put("city", city);
            }
        }
        return addressMap;
    }

    public static void main(String[] args) {
        System.out.println(getAddressInfo("上海浦东区"));
    }
}
